package main.java.indi.zyj.coderecord;

public class _02_minSubArrayLen {

    public int minSubArrayLen(int target, int[] nums) {

        int left = 0, right = 0;
        int vaildLen = Integer.MAX_VALUE, windowSum = 0;

        while (right < nums.length){

            windowSum += nums[right];
            right++;

            while (windowSum >= target && left <= right){
                vaildLen = Math.min(vaildLen, right - left);
                windowSum -= nums[left];
                left++;
            }

        }

        return vaildLen == Integer.MAX_VALUE ? 0 : vaildLen;

    }


}
